package com.sixkey.controller;


import com.sixkey.annotation.OperationLog;
import com.sixkey.entity.Message;
import com.sixkey.entity.vo.MessageVo;
import com.sixkey.response.Response;
import com.sixkey.service.IMessageService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2023-10-27
 */
@Slf4j
@Validated
@CrossOrigin
@RestController
@RequestMapping("/message")
@RequiredArgsConstructor
public class MessageController {

    private final IMessageService messageService;

    /**
     * 分页获取通知数据
     * @return
     */
    @GetMapping("/list/{pageNo}/{pageSize}")
    public Response list(@PathVariable("pageNo") Integer pageNo,
                         @PathVariable("pageSize") Integer pageSize) {
        log.info("分页查询通知数据请求进来");
        Map<String,Object> map = messageService.queryList(pageNo,pageSize);
        return Response.success(map);
    }

    /**
     *
     * @param
     * @return
     */
    @PostMapping("/save")
    public Response saveMessage(@RequestBody MessageVo messageVo) {
        //TODO:等登录功能开发完来完善
        messageService.saveMessage(messageVo);
        return Response.success();
    }

    /**
     * 修改通知
     * @param message
     * @return
     */
    @PutMapping("/update")
    @OperationLog("修改通知")
    public Response update(@RequestBody @Valid Message message){
        log.info("修改通知请求进来");
        messageService.updateById(message);
        return Response.success();
    }

    /**
     * 删除通知
     * @param
     * @return
     */
    @DeleteMapping("/remove/{id}")
    @OperationLog("删除通知")
    public Response remove(@PathVariable("id") List<Integer> id){
        log.info("删除通知请求进来");
        messageService.removeBatchByIds(id);
        return Response.success();
    }

    /**
     * 通知数据回显
     * @param
     * @return
     */
    @GetMapping("/echo/{id}")
    public Response getMessageInfo(@PathVariable("id") Integer id){
        log.info("通知回显请求进来");
        Message message = messageService.getById(id);
        return Response.success(message);
    }
}
